package com.czl.module_activity.fragment

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.czl.base.base.BaseFragment
import com.czl.base.config.AppConstants
import com.czl.module_activity.BR
import com.czl.module_activity.R
import com.czl.module_activity.adapter.ActivityAdapter
import com.czl.module_activity.adapter.MyActivityAdapter
import com.czl.module_activity.databinding.FragmentMyActivityBinding
import com.czl.module_activity.viewmodel.MyActivityViewModel

@Route(path = AppConstants.Router.Activities.F_ACTIVITIES_MY)
class MyActivityFragment:BaseFragment<FragmentMyActivityBinding,MyActivityViewModel>(){

    private lateinit var mAdapter: MyActivityAdapter
    override fun initContentView(): Int {
        tag
        return R.layout.fragment_my_activity
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }
    override fun initData() {
        viewModel.tvTitle.set("我的活动")
        initAdapter()
        reload()
    }
    private fun initAdapter() {
        mAdapter = MyActivityAdapter(this)
        binding.ryCommon.apply {
            layoutManager = LinearLayoutManager(context, RecyclerView.VERTICAL, false)
            adapter = mAdapter
        }
    }
    override fun initViewObservable() {
        viewModel.uc.refreshListEvent.observe(this, {
            binding.smartCommon.autoRefresh()
        })
        viewModel.uc.loadCompleteEvent.observe(this, { data ->
            handleRecyclerviewData(
                data == null,
                data?.records as MutableList<*>?,
                mAdapter,
                binding.ryCommon,
                binding.smartCommon,
                viewModel.currentPage,
                data?.current == data?.pages
            )
        })
    }
    override fun reload() {
        super.reload()
        binding.smartCommon.autoRefresh()
    }
}